﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BusinessObjects;
using System.Collections.Generic;

namespace MainGameModule.ViewModels
{
    public sealed class GameTaskManager
    {
        private Queue<SimpleTask> pendingTasks;
        private static GameTaskManager instance;

        private GameTaskManager()
        {
            this.pendingTasks = new Queue<SimpleTask>();
        }

        public static GameTaskManager Instance
        {
            get
            {
                if ( instance == null )
                    instance = new GameTaskManager();

                return instance;
            }
        }

        public event EventHandler PendingTasksAvailable;

        public Action AnimationFinished;

        public void ClearAllTasks()
        {
            this.pendingTasks.Clear();
        }

        public SimpleTask GetPendingTask()
        {
            return pendingTasks.Count > 0 ? pendingTasks.Dequeue() : null;
        }

        public void PublishTask( SimpleTask task )
        {
            this.pendingTasks.Enqueue( task );
            this.RaisePendingTaskAvailable();
        }

        private void Reset()
        {
            this.pendingTasks.Clear();
        }

        private void RaisePendingTaskAvailable()
        {
            var handler = this.PendingTasksAvailable;
            if ( handler != null )
            {
                handler( this, EventArgs.Empty );
            }
        }
    }
}
